<html>
<body onload="window.close();">

<?php 

$sequence_id = $_SERVER['REQUEST_TIME']."_";
$extention = ".dat";
$remote_backup_location = "H:\\\\211\\\\Follow-up Access Data\\\\211QA_Backup\\\\Data\\\\";
$local_backup_location = "E:\\\\EasyPHP5.3.0\\\\www\\\\QA\\\\Backup\\\\";
$tables_file = "data_tables.txt";
$max_runtime = 6000;


//echo "Maximum script runtime set to ".$max_runtime." seconds.<BR>";
set_time_limit($max_runtime);
error_reporting('IGNORE_REPEATED_ERRORS');

$conn = mysql_connect ("localhost", "root", "") or die ('Error: ' . mysql_error());
$db = mysql_select_db("QA");


$handle = @fopen($tables_file, "r");
//echo "Tables file opened: ".$tables_file." with handle ".$handle."<BR>";
if ($handle) {
        $source = null;
        $buftok[] = null;
	while (!feof($handle)){
		$bufferin = fgets($handle);
                $bufferin = trim($bufferin);
                if(strlen(trim($bufferin))>0){
		    $table_name = mysql_real_escape_string($bufferin);
                    $query_string = "SELECT * INTO OUTFILE \"".$local_backup_location.$sequence_id.$table_name.$extention."\" FROM ".$table_name.";";
                    $select_results = mysql_query($query_string);
		    //echo $query_string."<BR>";
                }
	}

     fclose($handle);   
}
echo "Backup complete (local).<BR>";

if( strlen($remote_backup_location)>0 ){
	$handle = @fopen($tables_file, "r");
	//echo "Tables file opened: ".$tables_file." with handle ".$handle."<BR>";
	if ($handle) {
	        $source = null;
        	$buftok[] = null;
		while (!feof($handle)){
			$bufferin = fgets($handle);
        	        $bufferin = trim($bufferin);
	                if(strlen(trim($bufferin))>0){
			    $table_name = mysql_real_escape_string($bufferin);
        	            $query_string = "SELECT * INTO OUTFILE \"".$remote_backup_location.$sequence_id.$table_name.$extention."\" FROM ".$table_name.";";
	                    $select_results = mysql_query($query_string);
			    //echo $query_string."<BR>";
        	        }
		}

	     fclose($handle);   
	}
	echo "Backup complete (remote).<BR>";
}

?><BR>
</body>
</html>